package com.kc.zhaojiu.controller;

import com.kc.zhaojiu.entity.TbCompany;
import com.kc.zhaojiu.service.TbCompanyService;
import com.kc.zhaojiu.util.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Author: QiongKe~
 * Date: 2022/10/24 2:06
 */
@Slf4j
@RestController
@RequestMapping("/companys")
public class TbCompanyController extends BaseController {
    @Autowired
    private TbCompanyService tbCompanyService;

//    @GetMapping("/getCompanyInfo")
//    public JsonResult<TbCompany> getCompanyInfo(Long id){
//        TbCompany data = tbCompanyService.getCompanyInfo(id);
//        return new JsonResult<>(OK,data,"查询到了这个公司");
//    }

    @GetMapping("/teacherId/{teacherId}")
    public JsonResult<List<TbCompany>> getCompanyByTeaId(@PathVariable("teacherId") Long teacherId){
        List<TbCompany> data = tbCompanyService.getCompanyByTeaId(teacherId);

        return new JsonResult<>(OK,data,"查询成功");
    }

    @GetMapping("/companyName/{hrName}")
    public JsonResult<List<TbCompany>> getCompanyByName(@PathVariable("hrName") String hrName){
        List<TbCompany> data = tbCompanyService.getCompanyByName(hrName);
        return new JsonResult<>(OK,data,"查询成功");
    }

    @PutMapping()
    public JsonResult<TbCompany> modCompanyInfo(@RequestBody TbCompany tbCompany){
//        System.out.println("这里:"+tbCompany);
        Integer i = tbCompanyService.modCompanyInfo(tbCompany);
        return new JsonResult<>(OK,"修改成功");
    }


    @DeleteMapping("/companyId/{id}")
    public JsonResult<TbCompany> moveCompany(@PathVariable("id")Long id){
        Integer i = tbCompanyService.moveCompany(id);

        return new JsonResult<>(OK,"删除成功");

    }

    @PostMapping()
    public JsonResult<TbCompany> addCompany(@RequestBody TbCompany tbCompany){

        Integer integer = tbCompanyService.addCompany(tbCompany);
        return new JsonResult<>(OK,"添加成功😋😋😋😋");
    }









}
